home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/memory.h>
- #include <powerup/gcclib/powerup_protos.h>
- #include <powerup/ppclib/object.h>
- //#include <stdio.h>
-
- #define Add(a,b) \
- ({ \
- if (!AddFuncPtr) \
- { \
- if (!(AddFuncPtr=PPCGetLibSymbol(LibObject,"Add"))) \
- { \
- /*PPCAlert(0x87000000);*/ \
- } \
- } \
- (*AddFuncPtr)(##a,##b); \
- })
-
- #define Sub(a,b) \
- ({ \
- if (!SubFuncPtr) \
- { \
- if (!(SubFuncPtr=PPCGetLibSymbol(LibObject,"Sub"))) \
- { \
- /*PPCAlert(0x87000000);*/ \
- } \
- } \
- (*SubFuncPtr)(##a,##b); \
- })
-
- /*
- * This uses a macro varargs extension to gcc
- * The only wait to pass ... to ... functions.
- */
-
-
- #define Print(a,b...) \
- ({ \
- if (!PrintFuncPtr) \
- { \
- if (!(PrintFuncPtr=PPCGetLibSymbol(LibObject,"Print"))) \
- { \
- /*PPCAlert(0x87000000);*/ \
- } \
- } \
- (*PrintFuncPtr)(##a,##b); \
- })
-
-
- int (*AddFuncPtr)(int,int);
- int (*SubFuncPtr)(int,int);
- int (*PrintFuncPtr)(const char*,...);
-
- int main(void)
- {
- void *LibObject;
- struct TagItem Tags[5];
- int (*AddFunc)(int,int);
- int (*SubFunc)(int,int);
- int Result;
- ULONG *Version;
- ULONG *Revision;
-
- Result = 0;
- Tags[0].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib without version or revision\n");
- AddFunc =(int (*)(int,int)) PPCGetLibSymbol(LibObject,
- "Add");
- SubFunc =(int (*)(int,int)) PPCGetLibSymbol(LibObject,
- "Sub");
-
- Version =(ULONG*) PPCGetLibSymbol(LibObject,
- "__LIB_Version");
- Revision =(ULONG*) PPCGetLibSymbol(LibObject,
- "__LIB_Revision");
- if (Version || Revision)
- {
- PPCprintf("Library Version %ld.%ld\n",
- *Version,
- *Revision);
- }
-
- if (AddFunc)
- {
- Result=(*AddFunc)(10,30);
- Result=(*SubFunc)(Result,20);
-
- PPCprintf("Example 10+30-20=%ld\n",
- Result);
- }
-
- // Result={(*AddFunc)(10,30);}
-
- Result=Add(100,300);
- Result=Sub(Result,200);
-
- Print("Example %ld+%ld-%ld=%ld\n",
- 100,
- 300,
- 200,
- Result);
-
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib without version or revision\n");
- }
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 30;
- Tags[1].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 30\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 30\n");
- }
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 50;
- Tags[1].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 50\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 50\n");
- }
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 30;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 650;
- Tags[2].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 30 revision 650\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 30 revision 650\n");
- }
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 41;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 667;
- Tags[2].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 41 revision 667\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 41 revision 667\n");
- }
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 42;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 666;
- Tags[2].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 42 revision 666\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 42 revision 666\n");
- }
-
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 42;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 667;
- Tags[2].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with version 42 revision 667\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with version 42 revision 667\n");
- }
-
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 41;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 666;
- Tags[2].ti_Tag = PPCELFLOADTAG_LIBEXACTVERSION;
- Tags[2].ti_Data = TRUE;
- Tags[3].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with exact version 41 and revision 666\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with exact version 41 and revision 666\n");
- }
-
-
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 42;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 665;
- Tags[2].ti_Tag = PPCELFLOADTAG_LIBEXACTVERSION;
- Tags[2].ti_Data = TRUE;
- Tags[3].ti_Tag = PPCELFLOADTAG_LIBEXACTREVISION;
- Tags[3].ti_Data = TRUE;
- Tags[4].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with exact version 42 and exact revision 665\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with exact version 42 and exact revision 665\n");
- }
-
-
- Tags[0].ti_Tag = PPCELFLOADTAG_LIBVERSION;
- Tags[0].ti_Data = 42;
- Tags[1].ti_Tag = PPCELFLOADTAG_LIBREVISION;
- Tags[1].ti_Data = 666;
- Tags[2].ti_Tag = PPCELFLOADTAG_LIBEXACTVERSION;
- Tags[2].ti_Data = TRUE;
- Tags[3].ti_Tag = PPCELFLOADTAG_LIBEXACTREVISION;
- Tags[3].ti_Data = TRUE;
- Tags[4].ti_Tag = TAG_END;
-
- if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
- Tags))
- {
- PPCprintf("opened lib with exact version 42 and exact revision 666\n");
- PPCCloseLibrary(LibObject);
- }
- else
- {
- PPCprintf("failed to open lib with exact version 42 and exact revision 666\n");
- }
-
- return(0);
- }
-